<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();


echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/vpsType.js?v='. OT_VERSION .'"></script>
');


switch ($mudi){
	case 'manage':
		$MB->IsSecMenuRight('alertBack',311,$dataType);
		manage();
		break;

	default:
		die('err');
}

$skin->WebBottom();

$MB->Close();
$DB->Close();





function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataMode	= OT::GetStr('dataMode');
	$dataModeStr= OT::GetStr('dataModeStr');

	$classArr = $companyArr = array();
	$classOptionStr = $companyOptionStr = $currClass = '';

	// $payArr = AdmArea::GetAppIdArr();	// 获取已购买插件appID数组 where VC_appID in ('. implode(',',$payArr) .')
	$apiArr = IdcArea::VpsApiArr('','name');	// 获取接口类型数组


	$classID = 0;
	$classWhere = $whereStr = '';
	switch ($dataMode){
		case 'host':
			$classID = 1;
			break;
	
		case 'vpsApi':
			$classID = 2;
			break;
	
		case 'serv':
			$classID = 3;
			break;
	
		case 'dialing':
			$classID = 5;
			break;
	
		case 'ssl':
			$classID = 6;
			break;
	
		case 'idcServ':
			$classID = 7;
			break;
	}
	if ($classID > 0){
		$classWhere = ' VC_ID='. $classID .' and ';
		$whereStr = ' where VT_classID='. $classID;
	}


	$classexe = $DB->query('select VC_ID,VC_theme,VC_state from '. OT_dbPref .'vpsClass where '. $classWhere .'VC_appID<>999 order by VC_rank ASC');
	while ($row = $classexe->fetch()){
		$classArr[$row['VC_ID']]	= $row['VC_theme'];
		if ($row['VC_state'] == 1){ $classOptionStr .= '<option value="'. $row['VC_ID'] .'">'. $row['VC_theme'] .'</option>'; }
	}
	unset($classexe);

	$companyexe = $DB->query('select VC_ID,VC_theme,VC_area,VC_isApi,VC_apiID,VC_state from '. OT_dbPref .'vpsCompany order by VC_rank ASC');
	while ($row = $companyexe->fetch()){
		$apiStr = '';
		if ($row['VC_isApi'] == 1){
			if (isset($apiArr[$row['VC_apiID']])){
				$apiStr = '<img src="images/usb.png" style="margin:0 2px;" align="top" title="API接口：'. $apiArr[$row['VC_apiID']] .'" alt="API接口：'. $apiArr[$row['VC_apiID']] .'" />';
			}else{
				$apiStr = '<img src="images/usb.png" style="margin:0 2px;" align="top" class="gray" title="API接口：未知'. $row['VC_apiID'] .'" alt="API接口：未知'. $row['VC_apiID'] .'" />';
			}
		}
		$companyArr[$row['VC_ID']]	= $row['VC_theme'] . $apiStr;
		if ($row['VC_state'] == 1){
			$companyOptionStr .= '<option value="'. $row['VC_ID'] .'" title="'. $row['VC_area'] .'">'. $row['VC_theme'] .'</option>';
		}
	}
	unset($companyexe);


	$skin->TableTop2('share_list.gif','',$dataTypeCN .'管理');
	$skin->TableItemTitle('4%,5%,6%,20%,6%,17%,17%,8%,8%,9%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,编号,ID,产品类型名称,数量,产品模块,上级渠道商,排序,状态,修改　删除');

	$pageSize	= 300;		// 每页条数$MB->mMbRow['MB_itemNum']
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit("select * from ". OT_dbPref ."vpsType ". $whereStr ." order by VT_classID ASC,VT_rank ASC",$pageSize,$page);
	if (! $showRow){
		// $skin->TableNoData();
	}else{
		$recordCount=$DB->GetRowCount();
		$pageCount=ceil($recordCount/$pageSize);
		if ($page < 1 || $page > $pageCount){$page=1;}

		echo('
		<tbody class="tabBody padd3td">
		');
		$number=1+($page-1)*$pageSize;
		$rowCount = count($showRow);
		for ($i=0; $i<$rowCount; $i++){
			if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }
			if (isset($classArr[$showRow[$i]['VT_classID']]) && $currClass != $classArr[$showRow[$i]['VT_classID']]){
				$currClass = $classArr[$showRow[$i]['VT_classID']];
				echo('
				<tr><td id="adStopStr" colspan="12" class="padd8 pointer" align="center" style="font-weight:bold;background:#e9e7e7;color:blue;padding:5px;">
					→ 【'. $currClass .'】 ←
				</td></tr>
				');
			}
			$proNum = -1;
			switch ($showRow[$i]['VT_classID']){
				case 1:	// 虚拟主机
					if (AppHost::Jud()){
						$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'hostData where HD_typeID='. $showRow[$i]['VT_ID']);
					}
					break;
			
				case 2:	// 云服务器
					$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'vpsApiData where VAD_typeID='. $showRow[$i]['VT_ID']);
					break;
			
				case 3:	// 服务器租用
					if (AppServ::Jud()){
						$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'servData where SD_typeID='. $showRow[$i]['VT_ID']);
					}
					break;
			
				case 4:	// 服务器托管
					break;
			
				case 5:	// 拨号VPS
					if (AppDialing::Jud()){
						$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'dialingData where DD_typeID='. $showRow[$i]['VT_ID']);
					}
					break;
			
				case 6:	// SSL证书
					if (AppSsl::Jud()){
						$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'sslData where SD_typeID='. $showRow[$i]['VT_ID']);
					}
					break;
			
				case 7:	// 主控机器
					if (AppIdcServ::Jud()){
						$proNum = $DB->GetOne('select count(1) from '. OT_dbPref .'idcServPro where ISP_typeID='. $showRow[$i]['VT_ID']);
					}
					break;
			}

			echo('
			<tr id="data'. $showRow[$i]['VT_ID'] .'" '. $bgcolor .'>
				<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $showRow[$i]['VT_ID'] .'" /></td>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['VT_ID'] .'</td>
				<td align="center" style="'. ($showRow[$i]['VT_state'] == 0 ? 'color:#c9c9c9;' : '') .'">'. $showRow[$i]['VT_theme'] .'</td>
				<td align="center">'. $proNum .'</td>
				<td align="center">'. (isset($classArr[$showRow[$i]['VT_classID']]) ? $classArr[$showRow[$i]['VT_classID']] : '<span style="text-decoration:line-through;colr:#666;">'. $showRow[$i]['VT_className'] .'</span>') .'</td>
				<td align="center">'. (isset($companyArr[$showRow[$i]['VT_companyID']]) ? $companyArr[$showRow[$i]['VT_companyID']] : '<span style="text-decoration:line-through;colr:#666;">'. $showRow[$i]['VT_companyName'] .'</span>') .'</td>
				<td align="center">'. $showRow[$i]['VT_rank'] .'</td>
				<td align="center">'. Adm::SwitchBtn('vpsType',$showRow[$i]['VT_ID'],$showRow[$i]['VT_state'],'state','') .'</td>
				<td align="center">
					<img src="images/img_rev.gif" style="cursor:pointer;" onclick=\'DataDeal.location.href="vpsType_deal.php?mudi=send&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataID='. $showRow[$i]['VT_ID'] .'&typeNum='. $number .'"\' alt="" />&ensp;&ensp;
					<img src="images/img_del.gif" style="cursor:pointer;" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="vpsType_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['VT_theme']) .'&dataID='. $showRow[$i]['VT_ID'] .'"}\' alt="" />
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		');
	}
	unset($showRow);
		
	echo('
	<form method="post" id="dealForm" name="dealForm" action="vpsType_deal.php?mudi=add" onsubmit="return CheckForm()">
	<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'">\')</script>
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataID" name="dataID" value="0" />
	<tr>
		<td id="numID" align="center"><br /></td>
		<td align="center"><br /></td>
		<td align="center"><br /></td>
		<td align="center">
			<div id="themeBox" style="display:none;"><input type="text" id="theme" name="theme" size="25" style="width:180px;" /></div>
			<div id="themeMoreBox">
				<textarea id="themeMore" name="themeMore"  style="width:180px;height:80px;"></textarea>
				<div style="padding:2px;">如添加多个，一行一个</div>
			</div>
		</td>
		<td align="center"><br /></td>
		<td align="center">
			<select id="classID" name="classID" onchange="CheckCompanyID()">
				'. ($classID > 0 ? '' : '<option value=""></option>') .'
				'. $classOptionStr .'
			</select>
		</td>
		<td align="center">
			<select id="companyID" name="companyID">
				'. ($classID == 7 ? '<option value="999">默认（母机上选择）</option>' : '<option value=""></option>'. $companyOptionStr .'') .'
				
			</select>
		</td>
		<td align="center"><input type="text" id="rank" name="rank" size="3" value="'. (intval($DB->GetOne("select max(VT_rank) from ". OT_dbPref ."vpsType". $whereStr))+10) .'" onkeyUp="this.value=FiltInt(this.value)" /></td>
		<td align="center"><select id="state" name="state"><option value="1">显示</option><option value="0">隐藏</option></select></td>
		<td align="center"><input id="subButton" type="image" src="'. AdmTpl::ImgSrc('button_add') .'" /></td>
	</tr>
	</form>
	<script language="javascript" type="text/javascript">
	CheckCompanyID();
	</script>
	');

	/*
	$optionNum = 0;
	$optionStr = '';
	$showexe=$DB->query('select * from '. OT_dbPref .'idcProType where IPT_level=1 order by IPT_rank ASC');
	while ($row = $showexe->fetch()){
		$optionNum ++;
		$optionStr .= '<option value="'. $row['IPT_ID'] .'">'. $optionNum .'、'. $row['IPT_theme'] .'</option>';
	}
	unset($showexe);

	echo('
	<tr class="tabColorB padd5">
		<td align="left" colspan="20">
			<input type="button" value="全选" onclick="AllSelBox()" class="form_button1" />
			<input type="button" value="反选" onclick="RevSelBox()" class="form_button1" />
			<!-- &ensp;
			<input type="submit" value="批量删除" /> -->
			&ensp;&ensp;
			<select id="moreMoveTo" name="moreMoveTo" onchange="MoreMoveTo()">
				<option value="">批量添加到【IDC商品类别】</option>
				'. $optionStr .'
			</select>
			<input type="hidden" id="moreMoveToCN" name="moreMoveToCN" value="" />
		</td>
	</tr>
	');
	*/

	$skin->TableBottom2($pageCount, $pageSize, $recordCount);

}

?>